<template>
  <div class="login">
    <van-form @submit.native.prevent>
      <van-field
        v-model="users.mobile"
        name="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="users.pwd"
        type="password"
        name="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" @click="doLogin"
          >立即登陆</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
        users:{
            mobile: '',
            pwd:'',
        }
    };
  },
  mounted() {},
  methods: {
      //执行登陆
      doLogin(){
          if(this.users.mobile == "" ||this.users.pwd == ""){
              return false;
          }
          let url = this.$store.state.mobile.yxUrl;

          //格式化为formdata
          let formdata = new FormData();
          formdata.append('mobile',this.users.mobile)
          formdata.append('pwd',this.users.pwd)

          this.$axios.post(`${url}/user/m/login?deviceId=007&deviceName=monkey`,formdata).then(res=>{
              console.log(res);
              if(res.code == 500){
                  this.$toast.fail(res.msg);
                  return false;
              }else{//登陆成功
                let data = res.data;

                this.$store.commit('mobile/doLogin',data);

                this.$toast.success('登陆成功');

                this.$router.go(-1);
              }

          })
      }
  },
  computed: {},
  watch: {},
};
</script>

<style lang="scss" scoped>
.login{
    width: 90%;
    border: #dddddd 1px solid;
    padding: 10px;
    box-sizing: border-box;
    margin: 30px auto;

    .van-field{
        border: #dddddd 1px solid;
        margin-bottom: 10px;
    }
}
</style>